package com.awccis.admin.service.impl;

import com.awccis.admin.dao.AdminWastageOrderDao;
import com.awccis.admin.model.worder.WastageOrderBean;
import com.awccis.admin.model.worder.WastageOrderViewBean;
import com.awccis.admin.service.AdminWastageOrderService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author: txp
 * @date: 2018/8/1 on 下午9:41
 * @since: 1.0
 * @description:
 */
@Service
public class AdminWastageOrderServiceImpl implements AdminWastageOrderService {

    @Resource
    private AdminWastageOrderDao adminWastageOrderDao;

    /**
     * 添加流失订单信息
     *
     * @param hasDriver        是否已经分配司机
     * @param wastageOrderBean 流失订单信息
     * @return 执行结果
     */
    @Override
    public Boolean addWastageOrders(boolean hasDriver, WastageOrderBean wastageOrderBean) {
        boolean result;
        if (hasDriver) {
            result = adminWastageOrderDao.insertHasDriverWastageOrder(wastageOrderBean) == 1;
        } else {
            result = adminWastageOrderDao.insertNoDriverWastageOrder(wastageOrderBean) == 1;
        }
        return result;
    }

    /**
     * 查询流失订单的详细信息
     *
     * @return
     */
    @Override
    public List<WastageOrderViewBean> queryWastageOrders() {
        return adminWastageOrderDao.selectHasDriverWastageOrders();
    }

    /**
     * 查询当天的流失订单信息
     *
     * @return list
     */
    @Override
    public List<WastageOrderViewBean> queryToadyWastageOrders() {
        return adminWastageOrderDao.selectHasDriverTodayWastageOrders();
    }

    /**
     * 根据customerID查询乘客的流失订单信息
     *
     * @param customerId customerID
     * @return list
     */
    @Override
    public List<WastageOrderViewBean> queryWastageOrdersByCustomerId(int customerId) {
        return adminWastageOrderDao.selectHasDriverWastageOrdersByCustomerId(customerId);
    }

    /**
     * 根据driverID查询司机的流失订单信息
     *
     * @param driverId driverID
     * @return list
     */
    @Override
    public List<WastageOrderViewBean> queryWastageOrdersByDriverId(int driverId) {
        return adminWastageOrderDao.selectHasDriverWastageOrdersByDriverId(driverId);
    }

    /**
     * 查询指定天数的已获取司机的所有流失订单信息
     *
     * @param day 指定天
     * @return list
     */
    @Override
    public List<WastageOrderViewBean> queryWastageOrdersByTime(Date day) {
        return adminWastageOrderDao.selectHasDriverDateWastageOrders(day);
    }

    /**
     * 查询已经获取司机的流失订单信息
     *
     * @param queryType 查询类别
     * @param queryId   查询ID
     * @param day       指定天
     * @return list
     */
    @Override
    public List<WastageOrderViewBean> queryHasDriverWastageOrders(String queryType, int queryId, Date day) {
        List<WastageOrderViewBean> list;
        switch (queryType) {
            case "all":
                list = adminWastageOrderDao.selectHasDriverWastageOrders();
                break;
            case "today":
                list = adminWastageOrderDao.selectHasDriverTodayWastageOrders();
                break;
            case "customer":
                list = adminWastageOrderDao.selectHasDriverWastageOrdersByCustomerId(queryId);
                break;
            case "driver":
                list = adminWastageOrderDao.selectHasDriverWastageOrdersByDriverId(queryId);
                break;
            case "time":
                list = adminWastageOrderDao.selectHasDriverDateWastageOrders(day);
                break;
            default:
                list = null;
                break;
        }
        return list;
    }

    /**
     * 查询未获取司机的流失订单信息
     *
     * @param queryType 查询类别
     * @param queryId   查询ID
     * @param day       指定天
     * @return list
     */
    @Override
    public List<WastageOrderViewBean> queryNoDriverWastageOrders(String queryType, int queryId, Date day) {
        List<WastageOrderViewBean> list;
        switch (queryType) {
            case "all":
                list = adminWastageOrderDao.selectNoDriverWastageOrders();
                break;
            case "today":
                list = adminWastageOrderDao.selectNoDriverTodayWastageOrder();
                break;
            case "customer":
                list = adminWastageOrderDao.selectNoDriversWastageOrdersByCustomerId(queryId);
                break;
            case "time":
                list = adminWastageOrderDao.selectNoDriverDateWastageOrder(day);
                break;
            default:
                list = null;
                break;
        }
        return list;
    }
}
